<template>
	<view class="content">
		<image class="logo" src="/static/logo.png"></image>
		<text class="title">
			{{title}}
		</text>
		<view class="subtitle">
			{{subtitle}}
		</view>
		<view style="margin-top: 45px;width: 100%; text-align: center;">
			<u-button type="success" @click="handleLogin">微信一键登录</u-button>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: '耒耜AI大模型',
				subtitle: '农业领域全智AI大模型',
				showAuthTip: false,
				infoVisible: false,
				avatarUrl: '/static/user.png',
				nickname: ''
			}
		},
		onLoad() {
				//检测是否已经收权
		},
		methods: {
			//微信code登录
			handleLogin(){
				var _this = this;
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						console.log("uni.login");
						console.log(loginRes);
						var params = {
							code: loginRes.code
						}
						_this.api.login(params).then(lres => {
							if(lres.code==1){
								_this.$refs.uToast.show({
									type: 'success',
									title: '默认主题',
									message: "登录成功!",
									iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/error.png'
								});
								
								console.log(lres);
								uni.setStorageSync("token",lres.token);								
								uni.navigateTo({
									url:"/pages/index/index"
								})
							}
						})
					}
				});
			},
			onChooseAvatar(e) {
				this.avatarUrl = e.detail.avatarUrl;
			},
			getNickname(e) {
				this.nickname = e.detail.nickname;
			},
			handleAuthConfirm() {
				this.showAuthTip = false;
			},
			handleRefuse() {
				this.avatarUrl = '/static/user.png';
				this.nickname = "";
				this.infoVisible = false;
			},
			handleAuthOk() {
				if (this.nickname == "" || this.avatarUrl == "") {
					this.$refs.uToast.show({
						type: 'error',
						title: '默认主题',
						message: "请填写您的昵称",
						iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/error.png'
					});
					return;
				}
				this.infoVisible = false;
				uni.navigateTo({
					url: "/pages/index/index"
				})
			}
		}
	}
</script>

<style scoped>
	.u-button {
		border: none !important;

	}

	button {
		background: none;
		/* 去除背景色 */
		border: none;
		/* 去除边框 */
		outline: none;
		/* 去除点击后的轮廓 */
		padding: 0;
		/* 去除内边距 */
		margin: 0;
		/* 去除外边距 */
		cursor: pointer;
		/* 给予指针样式 */
		border-radius: 80px;
		overflow: hidden;
	}

	img {
		width: 100%;
		/* 根据需要设置图片宽度 */
		height: auto;
		/* 图片高度自适应 */
		display: block;
		/* 去除图片下方的空白 */
	}

	button:active {
		border: none;
	}

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 20px;
		margin: 40px;
	}

	.logo {
		height: 256rpx;
		width: 256rpx;
		margin-top: 80rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.title {
		font-size: 36rpx;
		color: #3c3c3e;
		font-weight: bold;
	}

	.subtitle {
		line-height: 60px;
		height: 60px;
	}
</style>